package com.vrv.im.util;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFDataFormat;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.Cell;

public class Util {

	public static List<String> getSplit(String str, String regex) {
		if (str == null || "".equals(str))
			return null;
		String[] strs = str.split(regex);
		return Arrays.asList(strs);
	}

	public static String getFileType(String fileName) {
		if (fileName == null || "".equals(fileName))
			return null;
		int lastindex = fileName.lastIndexOf(".");
		return fileName.substring(lastindex, fileName.length());
	}

	public static String getCellContent(Cell cell) {
		if (cell == null)
			return "";
		cell.setCellType(Cell.CELL_TYPE_STRING);
		return String.valueOf(cell.getStringCellValue()).trim();

	}

	public static long getDate(Cell cell) {
		if (cell == null)
			return 0;
		cell.setCellType(Cell.CELL_TYPE_NUMERIC);
		if (HSSFDateUtil.isCellDateFormatted(cell)) {
			@SuppressWarnings("unused")
			SimpleDateFormat sdf = null;
			if (cell.getCellStyle().getDataFormat() == HSSFDataFormat.getBuiltinFormat("yyyy-MM-dd")) {
				sdf = new SimpleDateFormat("yyyy/MM/dd");
				Date date = cell.getDateCellValue();
				return date.getTime();
			}
		}
		return 0;

	}
}
